package com.heyun.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.heyun.bean.HeyunService;
import com.heyun.service.impl.HeyunServiceImpl;
//这个文件和transfer是有共性的，都是访问然后返回
//映射名定为heyunService
@Controller
@RequestMapping("/heyunService")
public class HeyunServiceController {
	@Autowired
	private HeyunServiceImpl heyunServiceImpl;
  //初到本页面时为需要默认查询形成表格，命名为selectForShowTable（暂不考虑依条件查询），应当考虑分页了
	@ResponseBody
	@RequestMapping("/select")

	public Map listHeyunService(HeyunService heyunService,int currentPage){
		System.out.println("testselectForShowTable"); 
		Map map=heyunServiceImpl.listHeyunService(heyunService,currentPage);
		System.out.println(map.get("heyunServiceList"));//daozhe 
		return map;
	}
	//按条件查询的那个先放一放，尽力合并到第一项上
	//******(此处省略一万行代码![>.<]!)
	//到添加了，命名为insert,往后依旧
	@ResponseBody
	@RequestMapping("/insert")
	//添加时总是要先查到那个数据（OK）
	public int insertHeyunService(HeyunService heyunService){
		Date date=new Date();
		String createTime=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(date);
		heyunService.setCreateTime(createTime);
		System.out.println(heyunService.toString());
		int a=heyunServiceImpl.insertHeyunService(heyunService);
		return a;
	}
	//此处为修改需要事先做展示最为恰当，那样就需要前台ajax来后台异步查询一下
	@ResponseBody
	@RequestMapping("/update")
	public int updateHeyunService(HeyunService heyunService){
		Date date=new Date();
		if("已分配".equals(heyunService.getState())){
			String allocateTime=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(date);
			heyunService.setAllocateTime(allocateTime);
		}
		if("已处理".equals(heyunService.getState())){
			String dealTime=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(date);
			heyunService.setDealTime(dealTime);
		}
		if("已反馈".equals(heyunService.getState())){
			String feedbackTime=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(date);
			heyunService.setFeedbackTime(feedbackTime);
		}
		if("已归档".equals(heyunService.getState())){
			String archiveTime=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(date);
			heyunService.setArchiveTime(archiveTime);
		}
		System.out.println("喝晕"+heyunService);
		int a=heyunServiceImpl.updateHeyunService(heyunService);
		return a;
	}
	//此处为删除，或涉及批量删除
	@ResponseBody
	@RequestMapping("/delete")
	public int deleteHeyunService(HeyunService heyunService){
		System.out.println("testdelete");
		int a =heyunServiceImpl.deleteHeyunService(heyunService);
		return a;
	}
	/*//提交，就是单传入一个状态字符串，然后再更新页面
	@ResponseBody
	@RequestMapping("/updateExtra")
	public int updateExtra(HeyunService heyunService){
		System.out.println("testupdate");
		int a=heyunServiceImpl.updateHeyunServiceExtra(heyunService);
		return a;
	}*/
	//查看，一定是单个查看，故而要传入其id以为依据,但是我要放一个对象进去，形式上更统一一点
	@ResponseBody
	@RequestMapping("/selectExtra")
	public HeyunService getHeyunServiceExtra(HeyunService heyunService){
		System.out.println("/selectExtra");
		HeyunService heyunServiceResult=heyunServiceImpl.getHeyunServiceExtra(heyunService);
		System.out.println(heyunServiceResult);
		return heyunServiceResult;
	}
	//批量删除
		@ResponseBody
		@RequestMapping("/archives")
		public int deletesHeyunService(@RequestParam(value = "checkID[]") int[] checkID){
			/*for(int a:checkID){
				System.out.println("数组是-----"+a+"===");
			}*/
			System.out.println("testarchives");
			int a =heyunServiceImpl.archivesHeyunService(checkID);
			return a;
		}
}
